GDK W32: Preserve the target value for change_property()
authorРуслан Ижбулатов <lrn1986@gmail.com>
Sun, 26 Nov 2017 00:21:22 +0000 (00:21 +0000)
committerРуслан Ижбулатов <lrn1986@gmail.com>
Thu, 30 Nov 2017 04:17:26 +0000 (04:17 +0000)
We need to know the target atom value to know when we need to
do something with side-effects (since side-effects are expressed via
special target values). Previously, the code side-stepped that by looking
at the data type (which was rather unique for the one side-effect
target that we supported, signalled by the TARGETS target),
but for the DELETE target that seems to be no longer an option, hence the new
field to carry this information past the convert_selection() routine.

This prevents GDK from throwing a warning when trying to convert
a DELETE target, which has no format or data objects set.

The side-effects for the DELETE target happen earlier, in GTK layer.
By the point it gets to change_property(), it's a no-op.

https://bugzilla.gnome.org/show_bug.cgi?id=786509

gdk/win32/gdkdnd-win32.c
gdk/win32/gdkevents-win32.c
gdk/win32/gdkselection-win32.c
gdk/win32/gdkselection-win32.h

index fc4dfb0de0e17dc5d6f33202e67eb0f7bbf82157..cb7eaa5c37a9ad619a12fc70ac558f0b76a13755 100644 (file)
@@ -1057,6 +1057,7 @@ idataobject_getdata (LPDATAOBJECT This,
         {
           target = frec->target;
           win32_sel->property_change_transmute = frec->transmute;
+          win32_sel->property_change_target_atom = frec->target;
         }
     }
 
@@ -2130,6 +2131,7 @@ _gdk_win32_dnd_do_dragdrop (void)
   /* Delete dnd selection after successful move */
   if (hr == DRAGDROP_S_DROP && dwEffect == DROPEFFECT_MOVE)
     {
+      GdkWin32Selection *win32_sel = _gdk_win32_selection_get ();
       GdkEvent tmp_event;
 
       memset (&tmp_event, 0, sizeof (tmp_event));
@@ -2138,6 +2140,7 @@ _gdk_win32_dnd_do_dragdrop (void)
       tmp_event.selection.send_event = FALSE;
       tmp_event.selection.selection = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND);
       tmp_event.selection.target = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_DELETE);
+      win32_sel->property_change_target_atom = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_DELETE);
       tmp_event.selection.property = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND);
       g_set_object (&tmp_event.selection.requestor, drag_ctx->source_window);
       tmp_event.selection.time = GDK_CURRENT_TIME; /* ??? */
index 873d225227067a890f27061241a65193e0c5da26..a2cd67cf038d43bcc730c2e65c32f296080f9e99 100644 (file)
@@ -3815,6 +3815,7 @@ gdk_event_translate (MSG  *msg,
       property_change_data = g_new0 (STGMEDIUM, 1);
       win32_sel->property_change_data = property_change_data;
       win32_sel->property_change_format = msg->wParam;
+      win32_sel->property_change_target_atom = target;
 
       fixup_event (event);
       GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
index 5fd02a698e3af473ace1ee5304cb8af6d1cea29c..ce42d0d12dacc8b12b54a2e2a928846970cb0547 100644 (file)
@@ -357,6 +357,7 @@ gdk_win32_selection_init (GdkWin32Selection *win32_selection)
   win32_selection->dnd_data_object_target = NULL;
   win32_selection->property_change_format = 0;
   win32_selection->property_change_data = NULL;
+  win32_selection->property_change_target_atom = 0;
 
   atoms = g_array_sized_new (FALSE, TRUE, sizeof (GdkAtom), GDK_WIN32_ATOM_INDEX_LAST);
   g_array_set_size (atoms, GDK_WIN32_ATOM_INDEX_LAST);
@@ -894,6 +895,7 @@ send_targets_request (guint time)
   tmp_event.selection.property = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_GDK_SELECTION);
   tmp_event.selection.requestor = owner;
   tmp_event.selection.time = time;
+  win32_sel->property_change_target_atom = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_TARGETS);
 
   gdk_event_put (&tmp_event);
   win32_sel->targets_request_pending = TRUE;
@@ -2325,8 +2327,10 @@ _gdk_win32_selection_property_change (GdkWin32Selection *win32_sel,
                                       gint               nelements)
 {
   if (property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_GDK_SELECTION) &&
-      type == GDK_SELECTION_TYPE_ATOM) /* implies target == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_TARGETS) */
+      win32_sel->property_change_target_atom == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_TARGETS))
     {
+      win32_sel->property_change_target_atom = 0;
+
       if (win32_sel->clipboard_opened_for == INVALID_HANDLE_VALUE &&
           OpenClipboard (GDK_WINDOW_HWND (window)))
         {
@@ -2345,11 +2349,22 @@ _gdk_win32_selection_property_change (GdkWin32Selection *win32_sel,
           open_clipboard_timeout (NULL);
         }
     }
+  else if (property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND) &&
+           mode == GDK_PROP_MODE_REPLACE &&
+           win32_sel->property_change_target_atom == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_DELETE))
+    {
+      /* no-op on Windows */
+      win32_sel->property_change_target_atom = 0;
+    }
   else if (mode == GDK_PROP_MODE_REPLACE &&
-           (win32_sel->property_change_data == NULL ||
+           (win32_sel->property_change_target_atom == 0 ||
+            win32_sel->property_change_data == NULL ||
             win32_sel->property_change_format == 0))
     {
-      g_warning ("Setting selection property with 0x%p == NULL or 0x%x == 0", win32_sel->property_change_data, win32_sel->property_change_format);
+      g_warning ("Setting selection property with 0x%p == NULL or 0x%x == 0 or 0x%p == 0",
+                 win32_sel->property_change_data,
+                 win32_sel->property_change_format,
+                 win32_sel->property_change_target_atom);
     }
   else if (mode == GDK_PROP_MODE_REPLACE &&
            win32_sel->property_change_data != NULL &&
@@ -2396,6 +2411,7 @@ _gdk_win32_selection_property_change (GdkWin32Selection *win32_sel,
 
       win32_sel->property_change_format = 0;
       win32_sel->property_change_data = 0;
+      win32_sel->property_change_target_atom = 0;
     }
   else
     {
index ed65087244c42dc8ce2688f532db59465034af29..c3ed6cd45e4fc99e469be58bc515171964c93d77 100644 (file)
@@ -167,6 +167,8 @@ struct _GdkWin32Selection
   LPSTGMEDIUM       property_change_data;
   /* Carries the transmute field of the GdkSelTargetFormat from from idataobject_getdata() to property_change() */
   gboolean          property_change_transmute;
+  /* Carries the target atom from GDK_SELECTION_REQUEST issuer to property_change() */
+  GdkAtom           property_change_target_atom;
 
   /* TRUE when we are emptying the clipboard ourselves */
   gboolean          ignore_destroy_clipboard;